﻿using System;
using System.Web.UI;
using ElevatorSpeeches.Framework;

namespace ElevatorSpeeches.UI.WebForms.Controls
{
    /// <summary>
    /// Displays a speech passed to the control by the FormSpeech property
    /// </summary>
    public partial class DisplaySpeech : UserControl
    {
        private Speech _FormSpeech;
        public Speech FormSpeech
        {
            get
            {
                return _FormSpeech;
            }
            set
            {
                _FormSpeech = value;
                _LoadFormFromSpeech();
            }
        }


        private int _SpeechID;
        public int SpeechID
        {
            get { return _SpeechID; }
            set
            {
                _SpeechID = value;
                FormSpeech = Speech.Find(_SpeechID);                
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                _LoadFormFromSpeech();
        }

        private void _LoadFormFromSpeech()
        {
            Body.Text = FormSpeech.Body.ToHtml();
            ExtendedBody.Text = FormSpeech.ExtendedBody.ToHtml();
        }        
    }
}
